package com.sun.alen.mapper;

import com.sun.alen.entity.Teacher;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface TeacherMapper {

    @Insert("INSERT INTO teacher( teacherName,teacherPassword,teacherPhone,teacherPhoto,professionId) " +
            "VALUES( #{teacherName}, #{teacherPassword},#{teacherPhone},#{teacherPhoto},#{professionId})")
    boolean add(Teacher teacher);

    @Update("update teacher set teacherName=#{teacherName}, teacherPhone=#{teacherPhone}, teacherPhoto=#{teacherPhoto}, professionId=#{professionId} " +
            "where teacherId=#{teacherId}")
    boolean update(Teacher teacher);

    @Delete("delete from teacher where teacherId=#{id}")
    boolean delete(String id);

    @Select("select * from teacher where teacherName like #{input} limit #{start},#{pageSize}")
    List<Teacher> searchByName(String input, Integer start, Integer pageSize);

    @Select("select count(*) from teacher where teacherName like #{input} ")
    long countByName(String input);

    @Select("select * from teacher limit #{start},#{pageSize}")
    List<Teacher> list(Integer start, Integer pageSize);

    @Select("select count(*) from teacher ")
    long count();

    @Select("select * from teacher where professionId = #{id} ")
    List<Teacher> searchByProfession(int id);

    @Select("select * from teacher where teacherName like #{input}")
    List<Teacher> searchIdByName(String input);

    @Select("select * from teacher")
    List<Teacher> all();

    @Select("select * from teacher where professionId = #{id}")
    List<Teacher> getTeacherByPro(String id);

    @Select("select * from `teacher` where teacherName=#{teacherName} and teacherPassword=#{teacherPassword}")
    Teacher login(Teacher teacher);

    @Update("update `teacher` set teacherPassword=#{pass} where teacherPhone = #{phone}")
    boolean repass(String phone, String pass);

    @Update("update teacher set teacherPhone=#{teacherPhone}, teacherPhoto=#{teacherPhoto}" +
            "where teacherId=#{teacherId}")
    boolean updateImg(Teacher teacher);

    @Select("select * from teacher where teacherId = #{teacherId}")
    Teacher selectById(int teacherId);

    @Update("update teacher set teacherPassword=#{teacherPassword}" +
            "where teacherId=#{teacherId}")
    boolean updatePass(Teacher teacher);
}
